<template>
    <div id="userList">
        <div style="background-color: white;padding: 10px;">
            <el-table border :data="userList" style="width: 700px" height="650">
                <el-table-column prop="name" label="名称" width="180" />
                <el-table-column prop="code" label="代码" width="180" />
                <el-table-column prop="parent_code" label="上级代码" width="180" />
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-button type="primary" @click="resetpwd(scope.row)">重置密码</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- <el-button type="success" @click="adddivision()">添加区划</el-button> -->

    </div>
</template>

<script setup>
import { ElMessage, ElMessageBox } from 'element-plus';
import { onMounted, reactive } from 'vue';
import $sys from '../../api/sys';
const userList = ref([]);
const page = reactive({
    pagenum: 1,
    pagesize: 999
})
function getList() {
    $sys.getDivisionList(page).then(res => {
        if (res.code == 200) {
            userList.value = res.data.result;
        }
    });
}
onMounted(() => {
    getList();
});
function resetpwd(e) {
    ElMessageBox.confirm(
        '此操作将重置该用户密码为HNrk@1234,是否继续?',
        '警告',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        $sys.resetDivisionPWD(e.code).then(res => {
            if (res.code == 200) {
                ElMessageBox.confirm(
                    '该用户密码已重置为HNrk@1234,请提醒该用户立即修改密码！',
                    '提示',
                    {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        type: 'success',
                    }
                ).then(()=>{
                    ElMessage({
                        message: '密码重置成功！',
                        type:'success'
                    })
                }).catch(()=>{
                    ElMessage({
                        message: '密码重置成功！',
                        type:'success'
                    })
                })
            }
        })
    }).catch(() => {

    })
}

</script>

<style scoped lang="less">
#userList {
   padding: 20px;
}
</style>
